/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { DeviceScheduleModel } from '../../common/models/deviceschedulemodel';

export class CommandUtil {


    //日程模块显示日程的时候  需要在下面添加对应的设备以及方法
    static DeviceDataMap = new Map([
        // 加湿器
        ["61b953b52b2aa20288c07fa9_SmartHumidifier01", new DeviceScheduleModel(CommandUtil.parseHumidifierCommand)],
        //护花使者
        ["6135e8fc2cce4f028625ccc9_Wateringllh", new DeviceScheduleModel(CommandUtil.parseWateringCommand)],
        ["6135e8fc2cce4f028625ccc9_Watering01", new DeviceScheduleModel(CommandUtil.parseWateringCommand)]
    ])

    static parseHumidifierCommand(CommandStr:string):string{
        let commandObject = JSON.parse(CommandStr);
        if (commandObject.HumidifierStatus == "ON") {
            return "打开加湿器"
        } else {
            return "关闭加湿器"
        }
    }

    static parseWateringCommand(CommandStr:string):string{
        let commandObject = JSON.parse(CommandStr);
       return "开始浇水:"+commandObject.Capacity+"ml"
    }


    static getTextCommand(deviceConfig:string):string{
        let jsonObject = JSON.parse(deviceConfig);
        let strCommand = jsonObject[0].command
        return this.DeviceDataMap.get(jsonObject[0].deviceId).parseCommandFunction(strCommand)
    }


}